package com.gt.andr.tabactvttest;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TabHost;

public class TabActivityAndListForEachTab extends TabActivity implements OnGestureListener {

	private static final String LIST1_TAB_TAG = "List1";
	private static final String LIST2_TAB_TAG = "List2";

	private TabHost tabHost;
	GestureDetector gestureDetector;
	private GestureDetector gestureScanner;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		gestureScanner = new GestureDetector(this,this);
		setContentView(R.layout.main2forlisttabactivt);
		tabHost = getTabHost();
		Intent intent1; // Reusable Intent for each tab
		Intent intent2; // Reusable Intent for each tab
		// Create an Intent to launch an Activity for the tab (to be reused)
		intent1 = new Intent().setClass(this, List1Activity.class);
		intent2 = new Intent().setClass(this, List2Activity.class);
		// add views to tab host
		tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG).setIndicator(LIST1_TAB_TAG).setContent(intent1));
		tabHost.addTab(tabHost.newTabSpec(LIST2_TAB_TAG).setIndicator(LIST2_TAB_TAG).setContent(intent2));
		tabHost.setCurrentTab(0);
	}


	@Override
	public boolean onTouchEvent(MotionEvent me) {
		return gestureScanner.onTouchEvent(me);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return true;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

		System.out.println("1 \t" + e1.getX() + "," + e1.getY());
		System.out.println("2 \t" + e2.getX() + "," + e2.getY());
		System.out.println("VelocityX :" + velocityX);
		System.out.println("VelocityY :" + velocityY);
		float dispX = e2.getX() - e1.getX();
		float dispY = e2.getY() - e1.getY();
		if (Math.abs(dispX) >= 200 && Math.abs(dispY) <= 50) {
			// swipe ok
			if (dispX > 0) {
				// L-R swipe
				System.out.println("L-R swipe");
			} else {
				// R-L swipe
				System.out.println("R-L swipe");
			}
		}
		return true;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		return true;
	}

	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return true;
	}
}